package com.dong.sso_relogin.controller;

import com.dong.sso_common.beans.CommonResult;
import com.dong.sso_common.model.SmsCouponHistory;
import com.dong.sso_relogin.service.UmsCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠券管理Controller
 * Created by macro on 2018/8/29.
 */
@Controller
@Api(tags = "UmsCouponController", description = "用户优惠券管理")
@RequestMapping("/coupon")
public class UmsCouponController {
    @Autowired
    private UmsCouponService umsCouponService;



    @ApiOperation("获取用户优惠券列表")
    @ApiImplicitParam(name = "useStatus", value = "优惠券筛选类型:0->未使用；1->已使用；2->已过期",
            allowableValues = "0,1,2", paramType = "query", dataType = "integer")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<SmsCouponHistory>> list(@RequestParam(value = "useStatus", required = false) Integer useStatus
                                                     , @RequestHeader("memberId") Long memberId) {
        if(memberId ==2){
            throw  new IllegalArgumentException("非法参数异常");
        }
        
        List<SmsCouponHistory> couponHistoryList = umsCouponService.list(useStatus,memberId);
        
        
        return CommonResult.success(couponHistoryList);
    }

}
